//页面加载
$.ajax({
    url: '/recipese/User',
    type: 'POST',
    success: function (data) {
        console.log(data);
        if (data.code == 0) {
            console.log(data);
            $.each(data.data, function (index, value) {
                $("#panel").html($("#panel").html() + `
            <tr data-foodid="`+ value.FoodID + `">
              <th scope="row">`+ (index + 1) + `</th>
              <td>`+ value.FoodName + `</td>
              <td>`+ value.CollectionNum + `</td>
              <td>`+ value.Release_time.substr(0, 10) + `</td>
              <td><button class="btn btn-secondary"><a style="text-decoration: none;color:white" href="./details/${value.FoodID}">查看/修改</a></button>&nbsp;<button class="delete_ btn btn-secondary">删除</button></td>
            </tr>
            `)
            })
        } else if (data.code == 1) {
            $("#toast1_text").text('您没有发布的菜单')
            $('.toast').attr('class', 'toast align-items-center text-bg-primary border-0 fade show')
        }
        else {
            alert('请先登录')
            window.location.href = window.origin + '/html/login'
        }
    }
})

//删除
$('body').on('click', '.delete_', function () {
    let dele = $(this)
    $.ajax({
        url: '/recipe/delete',
        type: "POST",
        data: {
            FoodID: $(this).parent().parent().data().foodid
        },
        success: function (data) {
            if (data.code == 0) {
                $("#toast1_text").text('删除成功')
                $('.toast').attr('class', 'toast align-items-center text-bg-primary border-0 fade show')
                setTimeout(function () {
                    $('.toast').attr('class', 'toast align-items-center text-bg-primary border-0 fade')
                }, 1000)
                dele.parent().parent().remove()
            }
        }
    })
})